<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .erweima {
            position: relative;
            width: 160px;
            height: 160px;
            margin: 100px auto;
            border: 1px solid #ccc;
        }

        .erweima i {
            position: absolute;
            left: -13px;
            top: 0;
            width: 10px;
            height: 10px;
            border: 1px solid #ccc;
            font-size: 12px;
            line-height: 10px;
            color: #ccc;
            font-style: normal;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="erweima">
        <img src="../第一天对DOM元素的操作/images/code.png" alt="" >
        <i class="close_btn">x</i>
    </div>
    <script>
        //1.获取元素对象
        let close_btn=document.querySelector('.close_btn')
        let erweima=document.querySelector('.erweima')
        let IMG=document.querySelector('img')
        let isShow = true;
        //2.进行事件监听，指定事件源，和所做的操作
        close_btn.addEventListener('click',function(){
            // erweima.style.display='none'
            // IMG.style.display='none'
            if(isShow){
                IMG.style.display='none'
                isShow= false
            }else{
                
                IMG.style.display='block'
                isShow = true;
            }
           

        })

    </script>
</body>

</html>